﻿using OF.BLL.Dish;
using OF.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Common;
namespace OF.Web.user
{
    public partial class orderlist : BuyerAdminPage
    {
        BLL.Order.Order bll_order = new BLL.Order.Order();
        DAL.Buyer dal_buyer = new DAL.Buyer();
        string strWhere = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        public void Bind()
        {
            if (string.IsNullOrWhiteSpace(strWhere))
                strWhere = " buyerid =" + WebUtils.GetBuyerId();
            OFPager.RecordCount = bll_order.GetRecordCount(strWhere);
            rptList.DataSource = bll_order.GetPageList(strWhere, "", OFPager.CurrentPageIndex, OFPager.PageSize);
            rptList.DataBind();
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

   

        public string GetState(object state, object id)
        {
            int temp = Convert.ToInt32(state);
            string str = " <td><a href='orderdetail.aspx?orderid=" + id + "'>";
            string result = "";
            if (temp == (int)Enmus.ORDER_STATE.INIT)
                result = "<font color='red'>待处理</font>" + str + "查看";
            else if (temp == (int)Enmus.ORDER_STATE.CONFIRM_SUC)
                result = "处理中" + str + "处理";
            else if (temp == (int)Enmus.ORDER_STATE.CONFIRM_Fail)
                result = "不处理" + str + "查看";
            else if (temp == (int)Enmus.ORDER_STATE.COMPLETE)
                result = "已完成" + str + "查看";
            else if (temp == (int)Enmus.ORDER_STATE.CANCEL)
                result = "已取消" + str + "查看";
            else if (temp == (int)Enmus.ORDER_STATE.INVALID)
                result = "<font color='blue'>已失效</font>" + str + "查看";
            return result + "</a></td>";
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string sql = "";
            if (!string.IsNullOrWhiteSpace(txtkey.Text.Trim()))
            {
                sql = " (ordersn like '%" + txtkey.Text.Trim() + "%' or phone like '%" + txtkey.Text.Trim() + "%') and ";
            }
            var sc = new SearcherColletion(this);
            strWhere = sc.GetSqlWhere("basic");
            if (string.IsNullOrWhiteSpace(strWhere))
            {
                strWhere = sql + " buyerid = " + WebUtils.GetBuyerId();
            }
            else
            {
                strWhere += " and " + sql + " buyerid = " + WebUtils.GetBuyerId();
            }
            OFPager.SearchCriteria = strWhere;
            Bind();
        }
    }
}